package com.heer.gymnasium.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.heer.amap.utils.ToastUtil;
import com.heer.gymnasium.api.constants.IConstants;
import com.heer.gymnasium.api.constants.StaticValue;
import com.heer.gymnasium.module.order.views.PaidSuccessActivity;
import com.qict.xinba.R;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, IConstants.APPID_WX);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {

    }

    @Override
    public void onResp(BaseResp resp) {
        Log.d(TAG, "onPayFinish, errCode = " + resp.errCode + " -- " + resp.errStr);
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (resp.errCode == 0) {
                ToastUtil.show(getApplicationContext(), "支付成功");
                    PaidSuccessActivity.startActivity(this);
                    Log.d(TAG, "onPayFinish, 跳转成功界面  ");

            } else {
                ToastUtil.show(getApplicationContext(), "支付失败");
                finish();
            }
        }
    }
}